package com.xuecheng.content.api;

import com.xuecheng.base.model.PageParams;
import com.xuecheng.base.model.PageResult;
import com.xuecheng.content.model.dto.AddCourseDto;
import com.xuecheng.content.model.dto.CourseBaseInfoDto;
import com.xuecheng.content.model.dto.QueryCourseParamsDto;
import com.xuecheng.content.model.po.CourseBase;
import com.xuecheng.content.service.CourseBaseInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Description: // 类说明，在创建类时要填写
 * @ClassName: CourseBaseInfoController    // 类名，会自动填充
 * @Author: MYH          // 创建者
 * @Date: 2023/1/28 16:56   // 时间
 * @Version: 1.0     // 版本
 */
@Api(value = "课程管理相关的接口",tags = "课程管理相关的接口")
@RestController
public class CourseBaseInfoController {

    @Autowired
    private CourseBaseInfoService courseBaseInfoService;

    /**
     * 课程分页查询
     * @param params
     * @param queryCourseParamsDto
     * @return
     */
    @ApiOperation(value = "课程分页查询接口")
    @PostMapping("/course/list")
    public PageResult<CourseBase> list(PageParams params, @RequestBody QueryCourseParamsDto queryCourseParamsDto){

        //调用service获取数据
        PageResult<CourseBase> courseBasePageResult = courseBaseInfoService.queryCourseBaseList(params, queryCourseParamsDto);
        return courseBasePageResult;
    }


    /**
     * 新增课程
     * @param addCourseDto
     * @return
     */
    @ApiOperation("新增课程")
    @PostMapping("/course")
    public CourseBaseInfoDto courseBaseInfoDto(@RequestBody @Validated AddCourseDto addCourseDto){

        //获取当前用户所属培训机构的id
        Long companyId = 22L;

        //调用service
        CourseBaseInfoDto courseBase = courseBaseInfoService.createCourseBase(companyId, addCourseDto);
        return courseBase;
    }


    /**
     * 修改课程的接口：用于回显信息
     * @param courseId 课程id
     * @return 返回课程基本信息表和课程营销表
     */
    @GetMapping("/course/{courseId}")
    public CourseBaseInfoDto getCourseBaseInfoDtoById(@PathVariable("courseId") Long courseId){

        CourseBaseInfoDto courseBaseInfo = courseBaseInfoService.getCourseBaseInfo(courseId);
        return courseBaseInfo;
    }


    /**
     * 修改课程的接口
     * @param courseBaseInfoDto
     * @return
     */
    @PutMapping("/course")
    public CourseBaseInfoDto modifyCourseBase(@RequestBody @Validated CourseBaseInfoDto courseBaseInfoDto){

        Long companyId = 22L;
        CourseBaseInfoDto courseBaseInfoDto1 = courseBaseInfoService.modifyCourseBaseById(companyId,courseBaseInfoDto);
        return courseBaseInfoDto1;
    }


    /**
     * 删除课程:删除课程相关的基本信息、营销信息、课程计划、课程教师信息
     * @param id
     */
    @DeleteMapping("/course/{id}")
    public void delCourseBase(@PathVariable("id") Long id){

        Long companyId = 22L;
        courseBaseInfoService.delCourseBase(id,companyId);

    }




}
